#ifndef _AMPERE_Q80_
#define _AMPERE_Q80_

#include <stdlib.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <errno.h>

#include "programmer.h"
#include "spi.h"
#include <sys/mman.h>

#define MEM_DEV                     "/dev/mem"
#define SPI_CTRL_REG_BASE             0x100002670000
#define SPI_REG_LENGTH                0x10000
#define SPI_READ_BASE                 0x00000000
#define SPI_WRITE_BASE                0x00000000
#define SPI_CPU_INTERVAL              0x20000000000
#define SECTOR_SIZE                   0x10000

#define ERASE_4         0x20     
#define ERASE_32        0x52 
#define ERASE_64        0xD8
#define ERASE_D7        0xD7
#define ERASE_C4        0xC4
#define ERASE_DB        0xDB
#define ERASE_50        0x50
#define ERASE_81        0x81
#define ERASE_21        0x21
#define ERASE_5C        0x5C
#define ERASE_DC        0xDC

#define SPI_CFG_PORT_ADDR                0x00
#define SPI_WP_ADDR                      0x0c
#define SPI_CS_DELAY_ADDR                0x10
#define SPI_FLASH_CAPACITY               0x14
#define SPI_FLASH_FLUSH                  0x18
#define SPI_CMD_PORT_ADDR                0x20
#define SPI_ADDR_PORT_ADDR               0x24
#define SPI_HDATA_PORT_ADDR              0x28
#define SPI_LDATA_PORT_ADDR              0x2C
#define SPI_CS0_CFG_ADDR                 0x30
#define SPI_ACCESS_CMD_MODE_MASK         (0x3<<6) 
#define SPI_ACCESS_ADDR_MODE_MASK        (0x1<<5) 

#define MmioWrite32(addr, val)         *((volatile uint32_t *)(addr)) = (val)
#define MmioWrite8(addr, val)          *((volatile uint8_t *)(addr)) = (val)

#define MmioRead32(addr)         *((volatile uint32_t *)(addr))

typedef off_t     SPI_PHYS_ADDR;
typedef uint8_t   *SPI_VIRT_ADDR;
typedef size_t    MAP_SIZE;
typedef unsigned long long  UINT64;
typedef UINT64              UINTN;
typedef unsigned int        UINT32;

typedef struct _FT2500_FLASH_MEMMAP {
  SPI_VIRT_ADDR          spi_ctrl_reg_base_virt;
  SPI_VIRT_ADDR          spi_rd_base_virt;
  SPI_VIRT_ADDR          spi_wt_base_virt;
  UINT32                 size;
} AMPERE_FLASH_MEMMAP;

#endif